import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};
        int[][] array2 = new int[2][3];
        int[][] array3 = new int[][] {{1,2,3},{4,5,6}};
    }
    public static void reverse(int[] array){
        int left = 0;
        int right = array.length-1;
        while(left<right){
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            left++;
            right--;
        }
    }

    public static void main9(String[] args) {
        int[] array = {1,2,3,4,5,6};
        reverse(array);
        System.out.println(Arrays.toString(array));
    }

    public static void bobbleSort(int[] array){
        for (int i = 0; i < array.length; i++) {
            boolean flg = false;
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]>array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = true;
                }
            }
            if(flg == false){
                return;
            }
        }
    }

    public static void main8(String[] args) {
        int[] array = {2,4,5,1,3,7,9,8,10};
        bobbleSort(array);
        System.out.println(Arrays.toString(array));
    }

    public static int findkey(int key,int[] array){
        for (int i = 0; i < array.length; i++) {
            if(array[i] == key){
                return i;
            }
        }
        return -1;
    }

    public static int binarySearch(int[] array,int key){
        int left = 0;
        int right = array.length-1;
        while(left<=right){
            int mid = (left+right)/2;
            if(array[mid] == key){
                return mid;
            }else if(array[mid]<key){
                left = mid+1;
            }else{
                right = mid - 1;
            }
        }
        return  -1;
    }

    public static void main7(String[] args) {
        int[] array = {1,2,3,4,5};
        int Index = binarySearch(array,3);
        System.out.println(Index);
    }
    public static double vag(int[] array){
        int sum = 0;
        for (int x:array) {
            sum += x;
        }
        return sum*1.0/ array.length;
    }

    public static void main6(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(vag(array));
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = array.clone();
        System.out.println(Arrays.toString(copy));
    }

    public static void main4(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = new int[array.length];

            /*
            * 1.要拷贝哪个数组
            * 2.要从这个数组的哪个位置开始拷贝
            * 3.要拷贝到哪个数组
            * 4.要拷贝到这个数组的哪个位置开始
            * 5.要拷贝多大
            * */
        System.arraycopy(array,0,copy,0,array.length);
    }

    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = Arrays.copyOfRange(array,1,3);
        System.out.println(Arrays.toString(copy));
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = Arrays.copyOf(array,array.length);
        System.out.println(Arrays.toString(copy));
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = new int[array.length];

        for (int i = 0; i < array.length ; i++) {
            copy[i] = array[i];
        }

        System.out.println(Arrays.toString(copy));
    }

}
